package com.ruoyi.web.controller.product;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HhModel;
import com.ruoyi.system.service.IHhModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品添加模板Controller
 * 
 * @author ruoyi
 * @date 2021-06-15
 */
@RestController
@RequestMapping("/product/model")
public class HhModelController extends BaseController
{
    @Autowired
    private IHhModelService hhModelService;

    /**
     * 查询商品添加模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(HhModel hhModel)
    {
        startPage();
        List<HhModel> list = hhModelService.selectHhModelList(hhModel);
        return getDataTable(list);
    }

    /**
     * 导出商品添加模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:model:export')")
    @Log(title = "商品添加模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HhModel hhModel)
    {
        List<HhModel> list = hhModelService.selectHhModelList(hhModel);
        ExcelUtil<HhModel> util = new ExcelUtil<HhModel>(HhModel.class);
        return util.exportExcel(list, "商品添加模板数据");
    }

    /**
     * 获取商品添加模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:model:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return AjaxResult.success(hhModelService.selectHhModelById(modelId));
    }

    /**
     * 新增商品添加模板
     */
    @PreAuthorize("@ss.hasPermi('product:model:add')")
    @Log(title = "商品添加模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HhModel hhModel)
    {
        return toAjax(hhModelService.insertHhModel(hhModel));
    }

    /**
     * 修改商品添加模板
     */
    @PreAuthorize("@ss.hasPermi('product:model:edit')")
    @Log(title = "商品添加模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HhModel hhModel)
    {
        return toAjax(hhModelService.updateHhModel(hhModel));
    }

    /**
     * 删除商品添加模板
     */
    @PreAuthorize("@ss.hasPermi('product:model:remove')")
    @Log(title = "商品添加模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(hhModelService.deleteHhModelByIds(modelIds));
    }
}
